package com.baidu.service.impl;

import com.baidu.pojo.TbContent;
import com.baidu.utils.ResultResponse;
import com.baidu.vo.ContentCategortListVo;
import com.baidu.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.pojo.TbContentCategory;
import com.baidu.service.TbContentCategoryService;
import com.baidu.mapper.TbContentCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class TbContentCategoryServiceImpl extends ServiceImpl<TbContentCategoryMapper, TbContentCategory>
implements TbContentCategoryService{

    @Autowired
    TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public ResultResponse getContenCategortList(PageVo vo) {
        Page<TbContentCategory> page = new Page<>(vo.getCurrent(), vo.getSize());
        Page<TbContentCategory> tbContentCategoryPage = tbContentCategoryMapper.selectPage(page, null);
        return ResultResponse.SUCCESS(tbContentCategoryPage);
    }

    @Override
    public ResultResponse getContenCategortListSel(ContentCategortListVo vo) {

        QueryWrapper<TbContentCategory> wrapper = new QueryWrapper<>();
        if (vo.getName() != null && !vo.getName().equals("")){
            wrapper.lambda().like(TbContentCategory::getName,vo.getName());
        }

        Page<TbContentCategory> page = new Page<>(vo.getCurrent(), vo.getSize());
        Page<TbContentCategory> tbContentCategoryPage = tbContentCategoryMapper.selectPage(page,wrapper);
        return ResultResponse.SUCCESS(tbContentCategoryPage);
    }

    @Override
    public ResultResponse addContentCategort(TbContentCategory contentCategory) {
        int insert = tbContentCategoryMapper.insert(contentCategory);
        return ResultResponse.SUCCESS(insert);
    }

    @Override
    public ResultResponse updateContentCategort(TbContentCategory contentCategory) {
        int insert = tbContentCategoryMapper.updateById(contentCategory);
        return ResultResponse.SUCCESS(insert);
    }

    @Override
    public ResultResponse delContentCategortByIds(Integer[] ids) {
        List<Integer> list = new ArrayList<>();
        for (Integer id : ids) {
            list.add(id);
        }
        int i = tbContentCategoryMapper.deleteBatchIds(list);
        return ResultResponse.SUCCESS(i);
    }

    @Override
    public ResultResponse updateStateYes(String ids) {
        Integer update = tbContentCategoryMapper.updateStateYes(ids);
        return ResultResponse.SUCCESS(update);
    }

    @Override
    public ResultResponse updateStateNo(String ids) {
        Integer update = tbContentCategoryMapper.updateStateNo(ids);
        return ResultResponse.SUCCESS(update);
    }

    @Override
    public ResultResponse getContentCategoryAll() {
        List<TbContentCategory> contentCategoryList = tbContentCategoryMapper.selectList(null);
        return ResultResponse.SUCCESS(contentCategoryList);
    }
}




